package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.Dishservice;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.method.HandlerMethod;

import java.util.List;

/*
* 菜品管理
* */
@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品接口")
public class Disgcontroller {
    @Autowired
    private Dishservice dishservice;
    @PostMapping
    @ApiOperation("新增菜品")
    public Result save(@RequestBody DishDTO dishDTO){
        log.info("新增菜品");
dishservice.savewithflavor(dishDTO);
return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation( "分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
       log.info("分页查询");
      PageResult pageResult= dishservice.page(dishPageQueryDTO);
      return Result.success(pageResult);
    }
    @DeleteMapping
    @ApiOperation("菜品批量删除")
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除菜品");
        dishservice.delete(ids);
        return Result.success();
    }
//    直接返回dish对象不行，因为还要返回口味相关的信息，而dish对象中没有封装口味相关的信息
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result<DishVO> getById(@PathVariable Long id){
        log.info("查询产品");
        DishVO dishVO= dishservice.getByIdwithFlavor(id);
        return Result.success(dishVO);
    }
    @PutMapping
    @ApiOperation("修改菜品")
    public Result update(@RequestBody DishDTO dishDTO){
        log.info("修改菜品");
        dishservice.updatewithflavor(dishDTO);
        return Result.success();
    }
}
